-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TaskExecutor conformance to EventLoops #2732
base: main
Are you sure you want to change the base?
Conversation
c48fcba
to
a982359
Compare
// MARK: TaskExecutor conformance | ||
#if compiler(>=6.0) | ||
@available(macOS 9999.0, iOS 9999.0, watchOS 9999.0, tvOS 9999.0, *) | ||
extension SelectableEventLoop: NIOTaskEventLoopExecutor { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add conformance for AsyncTestingEventLoop and a fatalErroring conformance for EmbeddedEventLoop?
let loop1 = iterator.next()! | ||
let loop2 = iterator.next()! | ||
|
||
await self._runTests(loop1: loop1, loop2: loop2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test currently crashes:
Thread 4 Crashed:: NIO-ELT-0-#0
0 libswiftCore.dylib 0x19a319644 swift_getObjectType + 88
1 libswift_Concurrency.dylib 0x2617ea0e4 swift_task_enqueueImpl(swift::Job*, swift::SerialExecutorRef) + 160
2 libswift_Concurrency.dylib 0x2617ec890 swift::AsyncTask::flagAsAndEnqueueOnExecutor(swift::SerialExecutorRef) + 432
3 libswift_Concurrency.dylib 0x2617eacdc swift_task_switchImpl(swift::AsyncContext*, void (swift::AsyncContext* swift_async_context) swiftasynccall*, swift::SerialExecutorRef) + 640
4 swift-nioPackageTests 0x1080d5ca1 partial apply for closure #1 in closure #1 in TaskExecutorTests._runTests<A, B>(loop1:loop2:) + 1
5 swift-nioPackageTests 0x1080d4d3d thunk for @escaping @isolated(any) @callee_guaranteed @Sendable @async () -> (@out A) + 1
6 swift-nioPackageTests 0x1080d4e99 partial apply for thunk for @escaping @isolated(any) @callee_guaranteed @Sendable @async () -> (@out A) + 1
7 libswift_Concurrency.dylib 0x2617f1921 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
Why do we call swift_task_switchImpl
with a SerialExecutorRef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch is what checks if it can "switch" without releasing actor locks; it won't be able to switch when there's a task executor. I'll look into reproducing this though with a debug runtime to check.
Can we also add another benchmark for the |
ba8f9fb
to
6018f07
Compare
Performance results on my machine:
|
7d76649
to
8ec67a1
Compare
Add TaskExecutor conformance to EventLoops
Motivation
Swift 6 introduces the option to supply your own task executors to the Swift concurrency runtime (SE-0417). SwiftNIO's EventLoop should conform to the new TaskExecutor protocol to support running Swift concurrency Tasks on it. This will allow fewer context switches in Swift on server applications.
Modifications
SerialExecutor
)NIODefaultSerialEventLoopExecutor
toNIODefaultEventLoopExecutor
NIODefaultEventLoopExecutor
now also implementsTaskExecutor
protocolNIOTaskEventLoopExecutor
protocol that makes it easy for adopters to get a better implementationResult
Adopters can use ELs as task executors